// pages/submit/submit.js
const app = getApp()
Page({

  data: {
    term1:'再来一局',
    term2:'返回首页',
    correct:0,
    wrong:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      correct: app.globalData.corrects,
      wrong: app.globalData.wrongs
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  submit: function (e){
    var that=this;
    wx.request({
      url: 'https://tally.slickghost.com/demo2/Answer/saveAnswer',
      method: 'get',
      data: { 
        openID: app.globalData.openid,
        correctCount: app.globalData.correct + that.data.correct,
        errorCount: app.globalData.wrong + that.data.wrong,
        score: app.globalData.score + that.data.correct*2
      },
      success: function (res) {
        app.globalData.correct += that.data.correct;
        app.globalData.wrong += that.data.wrong;
        app.globalData.score += that.data.correct * 2;
      }
    });
      wx.navigateTo({
        url: '../home/home'
      });
  },
  back:function(e){
    var that = this;
    wx.request({
      url: 'https://tally.slickghost.com/demo2/Answer/saveAnswer',
      method: 'get',
      data: {
        openID: app.globalData.openid,
        correctCount: app.globalData.correct + that.data.correct,
        errorCount: app.globalData.wrong + that.data.wrong,
        score: app.globalData.score + that.data.correct * 2
      },
      success: function (res) {
        app.globalData.correct += that.data.correct;
        app.globalData.wrong += that.data.wrong;
        app.globalData.score += that.data.correct * 2;
      }
    });
    wx.switchTab({
      url: '../indexs/indexs'
    });
  }
})